package com.oltpbenchmark.api;

import java.util.TreeMap;

public class UserGroup implements Comparable<UserGroup> {
  private long id;
  private TransactionType trxnType = null;
  private int[] userRange = new int[]{0, 0};
  private int userCount = 0;

  public static int GNUM = 10;

  private static TreeMap<String, UserGroup> userGroups = new TreeMap<>();

  private UserGroup(long id, TransactionType trxnType){
    this.id = id;
    this.trxnType = trxnType;
  }

  public static synchronized UserGroup getInstance(long id, TransactionType trxnType){
    String key = "U"+id+"/"+trxnType.getName();
    return userGroups.getOrDefault(key, new UserGroup(id, trxnType));
  };

  public long getId() {
    return id;
  }

  public TransactionType getTrxnType(){
    return trxnType;
  }

  public int[] getUserRange(){
    return userRange;
  }

  public String toString() {
    return String.format("%s/%s", this.id, this.trxnType);
  }

  @Override
  public int compareTo(UserGroup o) {
    return (int)this.id - (int)o.id;
  }
}
